package com.xxxx.server.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.server.mapper.EmployeeRemoveMapper;
import com.xxxx.server.pojo.EmployeeRemove;
import com.xxxx.server.pojo.EmployeeRemoveBean;
import com.xxxx.server.pojo.Position;
import com.xxxx.server.pojo.RespPageBean;
import com.xxxx.server.service.IDepartmentService;
import com.xxxx.server.service.IEmployeeRemoveService;
import com.xxxx.server.service.IJoblevelService;
import com.xxxx.server.service.IPositionService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhanglishen
 * @since 2020-11-14
 */
@Service
public class EmployeeRemoveServiceImpl extends ServiceImpl<EmployeeRemoveMapper, EmployeeRemove> implements IEmployeeRemoveService {

    @Autowired
    private EmployeeRemoveMapper employeeRemoveMapper;

    @Autowired
    private IDepartmentService departmentService;

    @Autowired
    private IPositionService positionService;

    @Override
    public RespPageBean getList(Integer currentPage, Integer size, EmployeeRemoveBean employeeRemoveBean) {
        Page<EmployeeRemoveBean> page = new Page<>(currentPage, size);
        IPage<EmployeeRemoveBean> employeeIPage = employeeRemoveMapper.getList(page, employeeRemoveBean);
        List<EmployeeRemoveBean> collect = null;
        if(employeeIPage.getRecords().size()>0){
             collect = employeeIPage.getRecords().stream().map((n) -> {
                EmployeeRemoveBean employeeRemoveBean1 = new EmployeeRemoveBean();
                BeanUtils.copyProperties(n,employeeRemoveBean1);
                employeeRemoveBean1.setAfterJobName(positionService.getById(n.getAfterJobId()).getName());
                employeeRemoveBean1.setBeforeJobName(positionService.getById(n.getBeforeJobId()).getName());
                employeeRemoveBean1.setAfterDepName(departmentService.getById(n.getAfterDepId()).getName());
                employeeRemoveBean1.setBeforeDepName(departmentService.getById(n.getBeforeDepId()).getName());
                return employeeRemoveBean1;
            }).collect(Collectors.toList());
        }
        RespPageBean respPageBean = new RespPageBean(employeeIPage.getTotal(),collect);
        return respPageBean;
    }
}
